//
//  FirCirBgImageDataSource.m
//  tcpoctest
//
//  Created by apple on 13-5-3.
//  Copyright (c) 2013年 gump. All rights reserved.
//

#import "FirCirBgImageDataSource.h"

@implementation FirCirBgImageDataSource

-(id)init
{
    self = [super init];
    if(self)
    {
        iImage = [[UIImage alloc] init];
        BigImage = nil;
        bigimageDic = [[NSMutableDictionary alloc] init];
        pthread_mutex_init(&mutexfcbgi, 0);
        self.sendmail = @"";
        searchArr = [[NSMutableArray alloc] init];
    }
    
    return self;
}

-(void)AddImagePath:(NSString *)path withMail:(NSString *)mail
{
    pthread_mutex_lock(&mutexfcbgi);
    
    [bigimageDic setObject:path forKey:mail];
    
    pthread_mutex_unlock(&mutexfcbgi);
}

-(void)RemovePathByMail:(NSString *)mail
{
    pthread_mutex_lock(&mutexfcbgi);
    
    [bigimageDic removeObjectForKey:mail];
    
    pthread_mutex_unlock(&mutexfcbgi);
}

-(void)RemoveAll
{
    pthread_mutex_lock(&mutexfcbgi);
    
    [bigimageDic removeAllObjects];
    
    pthread_mutex_unlock(&mutexfcbgi);
}

-(NSString *)SearchFCBgImageByMail:(NSString *)mail
{
    NSString *str = @"";
    pthread_mutex_lock(&mutexfcbgi);
    
    str = [bigimageDic objectForKey:mail];
    if (str == nil || [str isEqualToString:@""]) {
        
        if (![searchArr containsObject:mail]) {
            [searchArr addObject:mail];
            [[DataControl shareControl].LCDS addLogicCommand:LC_FCR_GETGBI];
        }
    }
    
    pthread_mutex_unlock(&mutexfcbgi);
    
    return str;
}

-(NSString *)getPathByMail:(NSString *)mail
{
    NSString *str = @"";
    pthread_mutex_lock(&mutexfcbgi);
    
    str = [bigimageDic objectForKey:mail];
    
    pthread_mutex_unlock(&mutexfcbgi);
    
    return str;
}

-(NSMutableArray *)getSearchArr
{
    NSMutableArray *arr = nil;
    
    pthread_mutex_lock(&mutexfcbgi);
    
    arr = searchArr;
    
    pthread_mutex_unlock(&mutexfcbgi);
    
    return arr;
}

-(void)delSearchOjByMail:(NSString *)mail
{
    pthread_mutex_lock(&mutexfcbgi);
    
    [searchArr removeObject:mail];
    
    pthread_mutex_unlock(&mutexfcbgi);
}

@end
